//
//  RenYuanGuanLiVC.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/9.
//

#import "RenYuanGuanLiVC.h"
#import "RenYuanGuanLiListVC.h"
#import "CaoZuoJiLuListVC.h"
#import "SuoShuQiYeViewController.h"
@interface RenYuanGuanLiVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)  UITableView       *  tableView;
@property(nonatomic,strong) NSMutableArray       *  dataAry;
@property(nonatomic,strong) YLUserInfo * info;
@end

@implementation RenYuanGuanLiVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self layoutCustomNav:self.view title:@"人员管理"];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.info = [YLUserMgr fetchUser];
     self.dataAry = [NSMutableArray arrayWithArray:@[@"当前身份",@"操作记录",@"人员管理"]];
    [self createTableView];
}

-(void)createTableView{
    self.tableView = [[UITableView  alloc] initWithFrame:CGRectMake(0, LL_StatusBarAndNavigationBarHeight, ScreenWidth, B_HEIGHT - LL_StatusBarAndNavigationBarHeight-142-LL_TabbarSafeBottomMargin)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = UIColor.whiteColor;
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:[CommonTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[CommonTableViewCell reuseIdentifier]];
    [self.view addSubview:self.tableView];
    
    //判断是否是超管 如果是超管不能退出企业
    if (![[[MSStorageUtils shareInstance] userDefaultGet:EduitString_key] isEqualToString:EduitString]){
        UIButton *createButton = [UIButton buttonWithType:UIButtonTypeCustom];
        createButton.frame=CGRectMake(16, B_HEIGHT - 142, ScreenWidth - 32, 42);
        [createButton setTitle:@"退出企业" forState:UIControlStateNormal];
        createButton.backgroundColor = mainColor;
        [createButton setTitleColor:White_Color forState:UIControlStateNormal];
        [createButton createBordersWithColor:nil withCornerRadius:4.0 andWidth:0];
        [createButton addTarget:self action:@selector(createButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:createButton];
    }
}

-(void)createButtonClick{
    [self commitInfo];
}
-(void)commitInfo{
   
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:self.info.companyId forKey:@"id"];
    [params setObject:self.info.phone forKey:@"unboundPhone"];
    
    
    [MSNetworkManager postRevertUrl:POST_PersonDelete_URL params:params success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if (isSuccess) {
            showAlert(@"退出企业成功");
            YLUserInfo * info = [YLUserMgr fetchUser];
            info.companyId = @"";
            info.enterpriseName = @"";
            [YLUserMgr saveUser:info];
            SuoShuQiYeViewController *VC =[[SuoShuQiYeViewController alloc] init];
            VC.isFromeLogin = YES;
            VC.isFromeTuiChu = YES;
            [self.navigationController pushViewController:VC animated:YES];
        }
        
        
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:YES];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.dataAry.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
     return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CommonTableViewCell  *  cell =[tableView dequeueReusableCellWithIdentifier:[CommonTableViewCell reuseIdentifier]];
    if (!cell) {
        cell=[[CommonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[CommonTableViewCell reuseIdentifier]];
    }
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
    cell.nameLb.text=self.dataAry[indexPath.row];
    cell.contentTF.userInteractionEnabled=NO;
    cell.indexPath = indexPath;
    [cell setCurrentValueBlock:^(NSString * _Nonnull contentString, NSIndexPath * _Nonnull indexPath) {
   
    }];
    if (indexPath.row == 1||indexPath.row == 2) {
        cell.contentTF.hidden = YES;
        cell.rightImage.hidden = NO;
    } else {
        cell.contentTF.hidden = NO;
        cell.contentTF.text = kUserDefaultForKey(COMPANY_ROLE_NAME);
        cell.rightImage.hidden=YES;
    }
    if (indexPath.row == 0) {
        cell.nameLb.textColor=mainColor;
    } else {
        cell.nameLb.textColor=Black_Color;
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [CommonTableViewCell cellHeight];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
          
        }
        break;
        case 1:
        {
            CaoZuoJiLuListVC  *VC =[[CaoZuoJiLuListVC alloc] init];
            [self pushToNextController:VC];
        }
        break;
        case 2:
        {
            RenYuanGuanLiListVC *VC =[[RenYuanGuanLiListVC alloc] init];
            [self pushToNextController:VC];
        }
        break;
        default:
        break;
    }
}


@end
